<%--
  Created by IntelliJ IDEA.
  User: bobo
  Date: 2021/11/1
  Time: 19:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script src="/js/jquery.min.js"></script>
    <title>注册页面</title>
</head>
<body>
<form method="post" action="/user/login" id="f1">
    <p>
        账户名：<input name="username">
    </p>
    <p>
        账号: <input name="code" onblur="checkCode();" id="code"><span id="s1" style="color:red;"></span>
    </p>
    <p>
        密码：<input type="password" name="password" id="pwd">
    </p>
    <p>
        确认密码：<input type="password" name="repassword" onblur="checkPwd();" id="repwd"><span id="s2" style="color:red;"></span>
    </p>
    <p>
        家庭住址：<input name="address">
    </p>
    <input type="button" onclick="regist();" value="注册">
</form>
</body>
<script>
    var flag = false;//开关
    function checkCode() {//验证账号是否唯一
        var code = $("#code").val();
        $.post("/user/checkCode",{"code":code},function (data) {
            if (data=="OK"){
                flag = true;
                $("#s1").text("ok");
            }else {
                flag = false;
                $("#s1").text("账号已经存在");
            }
        },"text");
    }
    function checkPwd() {//验证密码是否一致
        var pwd = $("#pwd").val();
        var repwd = $("#repwd").val();
        if (pwd!=repwd){
            flag=false;
            $("#s2").text("两次输入的密码不一致");
        }else{
            flag=true;
            $("#s2").text("ok");
        }
    }
    function regist() {
        //一系列的验证
        if (flag){
            $("#f1").submit();
        }

    }
</script>
</html>
